import Toast from '@vant/weapp/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: '',
        resourceURL: wx.api.host + '/',
        record: {},
        product: [],
        after_sales: {},
        order: {},
        quantity: '',
        detailinfo: [],
        shopinfo: {},
        logisticsList: [],
        express_name: null,
        description: null,
        loading: false,
        descriptionText: null,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            id: options.id
        })
        // console.log(options.id);
        this.getOrderDetail()
    },

    // 详情
    getOrderDetail() {
        wx.http.get(wx.api.getorderdetail, {
            order_id: this.data.id
        }).then(res => {
            if (res.code == 1) {
                this.setData({
                    order: res.data.order,
                    // after_sales: res.data.order.after_sales,
                    // product: res.data.productinfo,
                    // record: res.data.record,
                    detailinfo: res.data.productinfo[0].detailinfo,
                    shopinfo: res.data.productinfo[0].shopinfo,

                })
                this.getLogistics()
            }
        })
    },

    // 物流跟踪
    getLogistics() {
        Toast.loading({
            message: '加载中...',
            duration: 0
        })
        wx.http.post(wx.api.OrderExpress, {
            order_id: this.data.id,
        }).then((res) => {
            // console.log(res);
            if (res.code == 1) {
                this.setData({
                    logisticsList: res.data.list.map(e => {
                        return {
                            ...e,
                            text: e.status,
                            desc: `${e.time}，${e.context}`
                        }
                    }),
                    express_name: res.data.express_name,
                    description: res.code,
                    loading: true,
                })
                Toast.clear()
            } else {
                this.setData({
                    description: res.code,
                    descriptionText: res.msg,
                })
            }
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})